package ActionLesson;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import javax.swing.JTextField;
import javax.swing.UIManager;

public class ActionFrame extends JFrame
{

    public ActionFrame() {
        actionPanel ap = new actionPanel();
        setSize(300, 250);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        add(ap);

    }

    class actionPanel extends JPanel
    {

        private Box mainBox;
        private JTextField tf;
        private UIManager um;

        public actionPanel() {
            mainBox = Box.createVerticalBox();
            um = new UIManager();
            textField();
            checkField();
            addButton();
            add(mainBox);
        }

        void textField() {
            tf = new JTextField("", 15);
            mainBox.add(tf);

        }

        private void addButton() {
            JPanel buttonPanel = new JPanel();
            JButton actionButton = new JButton("Go");
            actionButton.addActionListener(new chengeColor());
            buttonPanel.add(actionButton);
            mainBox.add(buttonPanel);
        }

        private void checkField() {
            //  JPanel checkButton = new JPanel();
            ButtonGroup group = new ButtonGroup();
            JRadioButton checkBoxRed = new JRadioButton("Выбрать красный цвет");
            group.add(checkBoxRed);
            checkBoxRed.addActionListener(new ActionListener()
            {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    um.put("OptionPane.messageForeground", Color.red);
                }
            });
            mainBox.add(checkBoxRed);

            JRadioButton checkBoxGreen = new JRadioButton("Выбрать зелёный цвет");
            group.add(checkBoxGreen);
            checkBoxGreen.addActionListener(new ActionListener()
            {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    um.put("OptionPane.messageForeground", Color.GREEN);
                }
            });

            mainBox.add(checkBoxGreen);

            JRadioButton checkBoxYellow = new JRadioButton("Выбрать желтый цвет");
            group.add(checkBoxYellow);
            checkBoxYellow.addActionListener(new ActionListener()
            {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    um.put("OptionPane.messageForeground", Color.YELLOW);
                }
            });
            mainBox.add(checkBoxYellow);

        }

        class chengeColor implements ActionListener
        {

            @Override
            public void actionPerformed(ActionEvent ae) {
                JOptionPane.showMessageDialog(null, tf.getText(), "Mess", JOptionPane.ERROR_MESSAGE, null);
            }

        }
    }
}
